import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { Dog, DogDocument } from './dog.schema';
import { CreateDogDto } from './dto/create.dto';

@Injectable()
export class DogService {
  constructor(@InjectModel(Dog.name) private dogModel: Model<DogDocument>) {}

  async create(createDogDto: CreateDogDto): Promise<Dog> {
    // return this.dogModel.create(createDogDto); // 直接内部实例化了，没法对实例进行操作，灵活度下降
    const dog = new this.dogModel(createDogDto);
    return dog.save();
  }

  // 获取所有用户
  async findAll(): Promise<Dog[]> {
    return this.dogModel.find().exec();
  }
}
